<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>我的问题</title>
    <link rel="stylesheet" href="../css/index.css"/>
    <link rel="stylesheet" href="../css/font-icons.css"/>
    <script src="../js/jquery-1.7.2.min.js"></script>
</head>
<body>
<div id="header">
    <span class="ti-user">用户：</span>
    <span class="userName"></span>
    <span class="enter">退出登录</span>
    <a href="html/modifyPassword.html"><span  class="amend"> 修改密码</span></a>
</div>
<div id="mine">
    <div id="theTop">
        <span>NC双百 我的战绩！! !</span>
    </div>
    <div id="search">
        <input type="text" placeholder="搜索BUG/需求名称、BUG/需求描述">
        <span class="ti-search">搜索</span>
    </div>
    <div id="tab">
        <ul>
            <li class="active" name="bug"><a class="BK" href="##" id="applied">我的BUG<span class="bugCount"></span></a>
            </li>
            <li name="demand"><a href="#" id="reviewing">我的需求<span class="demandCount"></span></a></li>
        </ul>
    </div>
    <div class="screening">
        <div class="region">
            <span> 大区：</span>
            <ul class="theDomain">
                <li class="colorChange">全部</li>
                <li>北京</li>
                <li>上海</li>
                <li>深圳</li>
                <li>浙江区</li>
                <li>苏皖区</li>
                <li>华南区</li>
                <li>福建区</li>
                <li>中南区</li>
                <li>西南区</li>
                <li>西北区</li>
                <li>津冀区</li>
                <li>东北区</li>
                <li>山东区</li>
                <li>央本-军工</li>
            </ul>
        </div>
        <div class="domain">
            <span> 领域：</span>
            <ul class="theDomain">
                <li class="colorChange">全部</li>
                <li>财务会计</li>
                <li>增值税管理平台</li>
                <li>报表</li>
                <li>合并报表</li>
                <li>电子采购</li>
                <li>产品成本</li>
                <li>资金管理</li>
                <li>资产管理</li>
                <li>人力资本</li>
                <li>全面预算</li>
                <li>供应链</li>
                <li>利润中心会计</li>
                <li>进出口</li>
                <li>应用平台</li>
                <li>CRM</li>
                <li>财务共享</li>
                <li>电子销售</li>
                <li>全渠道营销</li>
                <li>医药</li>
                <li>HR</li>
                <li>ECM</li>
                <li>生产制造</li>
                <li>交通公用</li>
                <li>NC升迁</li>
            </ul>
        </div>

    </div>
    <div id="mineShow">
        <span class="reminder">正在加载...</span>
        <div class="show">

        </div>
        <span class="nomore">没有更多数据</span>
        <div id="thePage">
            <p id="back">上一页</p>
            <ul id="yema">
            </ul>
            <p id="next">下一页</p>
            <p id="total"></p>
            <div id="tiao">
                <input type="text" id="inputNum"/>
                <span id="goTo">跳转</span>
            </div>
        </div>
    </div>

</div>
<div id="footer">
    <ul>
        <li>
            <a href="../index.html">
                <div>首页</div>
            </a>
        </li>
        <li>
            <a href="add.html">
                <div>添加</div>
            </a>
        </li>
        <li>
            <a href="caculate.html">
                <div>统计</div>
            </a>
        </li>
        <li class="active chooseCol">
            <a href="mine.html" class="active">
                <div>我的</div>
            </a>
        </li>
    </ul>
</div>
<script>
    $(function () {//分页
        if(localStorage.token != 'undefined'){
            jiazai(0)
        } else{
            alert('请先登录')
            window.location.href = 'login.html'
        }
        $('.userName').html(localStorage.userName);
        $('.enter').click(function(){
            localStorage.token = '';
            localStorage.userid = '';
            window.location.href = 'login.html'
        });
             localStorage .which = "mine";
        $('#tab li').children('a').removeClass('BK');
        if(localStorage .idName2){
            $('#tab li[name="'+localStorage .idName2+'"]').children('a').addClass('BK');
        }else{
            localStorage .idName2 = 'bug'
        }

        var areaname = '';
        var field = '';
        localStorage .setItem('areaname', areaname);
        localStorage .setItem('field', field);
        $('.region li').click(function () {
            var region = $(this).html();
            if (region == '全部') {
                areaname = ''
            } else {
                areaname = region
            }
            localStorage .setItem('areaname', areaname);
            $(this).addClass('colorChange').siblings('li').removeClass('colorChange');
            jiazai(0)
        });
        $('.domain li').click(function () {
            var domain = $(this).html();
            if (domain == '全部') {
                field = ''
            } else {
                field = domain
            }
            localStorage .setItem('field', field);
            $(this).addClass('colorChange').siblings('li').removeClass('colorChange');

            jiazai(0)
        });

        //切换数据
        $("#tab li").on("click", function () {
            $(".show").html("");
            $("#bug,#demand").html("");
            var idName = $(this).attr("name");
            localStorage .idName2 = idName;
            $(this).children('a').addClass('BK')
            $(this).siblings('li').children('a').removeClass('BK')
            $("div[id='" + idName + "']").show().siblings().hide().html();
//            $(this).addClass("active").siblings().removeClass("active");
            //调用接口查询数据
            jiazai(0)
        });
        function jiazai(num) {
            var num = Number(num);
            $('.msg').unbind();
            $('.show').html('');
//			============================================
            $('.reminder').show()
            $('.nomore').hide();
            $(".show").html("");
            if(localStorage .idName2){
                var idName = localStorage .getItem('idName2');
            } else{
                var idName = 'bug'
            }

            var params = {
                beginindex: 1 + num * 10,
                endindex: 10 + num * 10,
                param: JSON.stringify({
                    supporttype: idName,
                    creator: localStorage.token,
                    solvername: localStorage.username,
                    search: $('#search input').val(),
                    areaname: localStorage .areaname,
                    field: localStorage .field
                })

            };
            $.post(localStorage.location+"alldhsupports", params, function (data) {

                $('.delData').unbind();
                $(".bugCount").html("(" + (data.bugCount ? data.bugCount : 0) + ")");
                $(".demandCount").html("(" + (data.demandCount ? data.demandCount : 0) + ")");
                var length;
                if (idName == 'bug') {
                    length = Math.ceil(data.bugCount / 10);
                } else if (idName == 'demand') {
                    length = Math.ceil(data.demandCount / 10);
                }
                var bugcount = data.bugCount;
                var demandCount = data.demandCount;
                localStorage .setItem('pageZ', length);
                $('#total').html('共' + length + '页');
                var dataD = data.data;
                console.log(data)
                if(dataD.length == 0){
                    $('.reminder').hide()
                    $('.nomore').show();
                }else{
                    for (var i = 0; i < dataD.length; i++) {
                        var appendStr =
                                '<div class="msg">' +
                                '<a href="../html/detail.html?pk_support=' + dataD[i].pk_support + '">' +
                                '<p><span class="title">项目名称:</span><span class="text">' + (dataD[i].projectname ? dataD[i].projectname : "") + '</span></p>' +
                                '<p><span class="title">BUG名称:</span><span class="text">' + (dataD[i].supportname ? dataD[i].supportname : "") + '</span></p>' +
                                '<span class="title_C"><span class="title">大区:</span><span class="text">' + (dataD[i].areaname ? dataD[i].areaname : "") + '</span></span><span class="title_D"><span class="title">领域:</span><span class="text">' + (dataD[i].field ? dataD[i].field : "") + '</span></span>' +
                                '<span  class="title_E"><span class="title">录单时间：</span><span class="text">' + dataD[i].creationtime + '</span></span>' +
                                '</a>' +
                                (dataD[i].supportstatus == "已解决" ? '<span class="state">' + (dataD[i].supportstatus ? dataD[i].supportstatus : "") + '</span>' : "") +
                                (dataD[i].supportstatus == "进行中" ? '<span class="state doing">' + (dataD[i].supportstatus ? dataD[i].supportstatus : "") + '</span>' : "") +
                                (dataD[i].supportstatus == "未开始" ? '<span class=" notstart">' + (dataD[i].supportstatus ? dataD[i].supportstatus : "") + '</span>' : "") +
                                '<a class="delData" href="##">删除</a>' +
                                '<a href="change.html?pk_support=' + dataD[i].pk_support + '" class="change">修改</a>' +
                                '</div>';
                        $('.reminder').hide();
                        $(".show").append(appendStr);

                    }
                }

                yema(num + 1);
                $('.delData').click(function () {
                    var that = this;
                    var pk = $(this).next('a').attr('href').split('pk_support=')[1];
                    if (confirm("确定删除？")) {
                        $.post(localStorage.location+"deletedhsupport", {pk_support: pk}, function (data) {
                            if (data.status == 'success') {
                                alert("删除成功！");
                                $(that).parent().remove();
                                if (idName == 'bug') {
                                    bugcount--;
                                    $(".bugCount").html('('+bugcount+')');
                                } else if (idName == 'demand') {
                                    demandCount--;
                                    $(".demandCount").html('('+demandCount+')');
                                }
                            } else {
                                alert("删除失败！");
                            }
                        });
                    }
                })
            });

        };
        localStorage .setItem('page', 0);
        function yema(page) {
            var yeMa = $('#yema');
            $('.page').unbind();
            yeMa.html('');
            var page = Number(page);
            var lastPage = Number(localStorage .getItem("pageZ"));
            $('#total').html('共' + lastPage + '页')
            if (page < 5) {
                if (lastPage >= 0 && lastPage <= 6) {
                    for (var i = 1; i < lastPage + 1; i++) {
                        var li = '<li class="page">' + i + '</li>';
                        yeMa.append(li)
                    }
                } else if (lastPage > 6) {
                    for (var i = 1; i < 7; i++) {
                        var li = '<li class="page">' + i + '</li>';
                        yeMa.append(li)
                    }
                    var pageLast = '<p>...</p><li class="page">' + lastPage + '</li>';
                    yeMa.append(pageLast);

                }
            } else if (page >= 5 && page <= lastPage - 3) {
                var liOne = '<li class="page">1</li><p>...</p>';
                yeMa.append(liOne);
                for (var i = page - 2; i < page + 3; i++) {
                    var li = '<li class="page">' + i + '</li>';
                    yeMa.append(li)
                }
                var pageLast = '<p>...</p><li class="page">' + lastPage + '</li>';
                yeMa.append(pageLast);

            } else if (page >= lastPage - 3) {
                var liOne = '<li class="page">1</li><p>...</p>';
                yeMa.append(liOne);
                for (var i = page - 2; i < lastPage + 1; i++) {
                    var li = '<li class="page">' + i + '</li>';
                    yeMa.append(li)
                }
            }

            for (var i = 0; i < ('.page').length; i++) {
                if ($('.page').eq(i).html() == page) {
                    $('.page').eq(i).addClass('col')
                }
            }

            $('.page').click(function () {
                var thisNum = $(this).html();
                jiazai(thisNum - 1);
                localStorage .setItem('page', thisNum - 1)
            })

        }

        //上一页==================================
        $('#back').click(function () {
            var pageNum = localStorage .getItem('page');
            if (pageNum < 1) {
                pageNum = 1;
            }
            jiazai(pageNum - 1);
            pageNum--;
            localStorage .setItem('page', pageNum)
        });

        //下一页===================================
        $('#next').click(function () {
            var pageNum = localStorage .getItem('page');
            var lastPage = Number(localStorage .getItem("pageZ"));
            pageNum++;
            if (pageNum >= lastPage) {
                pageNum = lastPage - 1;
            }
            jiazai(pageNum);
            localStorage .setItem('page', pageNum)
        });

        //跳转页===================================
        $('#goTo').click(function () {
            var ye = $('#inputNum').val();
            var lastPage = Number(localStorage .getItem("pageZ"));
            if (!/^[1-9]\d*$/.test(ye)) {
                alert('请输入正整数');
            } else {
                if (ye > lastPage) {
                    ye = lastPage;
                }
                jiazai(ye - 1);
            }
            $('#inputNum').val('');
        });
        //搜索======================================
        $("#search input").on("keypress", function (event) {
            if (event.keyCode == "13") {
                $("#search input").blur();
                jiazai(0)
            }
        });
        $('.ti-search').click(function () {
            jiazai(0)
        }) ;
        $(document).scroll(function () {
            var stop = $(this).scrollTop();
            if (stop >= 100) {
                $('#search').addClass('toTop')
            } else {
                $('#search').removeClass('toTop')
            }
        })
    });

</script>
</body>
</html>